package com.xm.zcf.dao.category.impl;

import com.xm.zcf.action.Base.SessionBase;
import com.xm.zcf.dao.category.CategoryDao;
import com.xm.zcf.domain.category.Category;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/3/13.
 */
@Repository
public class CategoryDaoImpl extends SessionBase implements CategoryDao {

    @Override
    public List<Category> findAll() {
        return getSession().createQuery("from Category ").list();
    }

    @Override
    public Category findById(Integer cid) {
         Category category=(Category) getSession().createQuery(
                 "from Category c where c.cid=?"
         ).setParameter(0,cid)
          .uniqueResult();
         return category;
    }

    @Override
    public void deleteCategory(Category category) {
        getSession().delete(category);
    }

    @Override
    public void save(Category model) {
        getSession().save(model);
    }

    @Override
    public void update(Category category) {
        getSession().update(category);
    }
}
